package com.honour.controller.interfaced;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.honour.service.interfaced.impl.AdvertisementInService;
import com.system.controller.base.BaseController;
import com.system.util.AppUtil;
import com.system.util.PageData;
import com.system.util.Tools;

/**  广告栏接口
 @Function
 @Author zhaozhenhua
 @Date   2017年12月25日
*/
@Controller
@RequestMapping(value="/appadvertismentin")
public class AdvertiseInController extends BaseController{
	
	@Resource(name="advertisementInService")
	private AdvertisementInService advertisementInService;
	
	/**
	 * 根据广告栏位置查询广告
	 * @Author zhaozhenhua
	 * @date   2017年12月25日
	 * @return
	 */
	@RequestMapping(value="/advertiselist")
	@ResponseBody
	public Object getAdvertisementList(){
		logBefore(logger, "根据广告栏位置查询广告");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("ADVERTISEMENTLIST", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("advertisementList", pd)){	//检查参数
					 List<PageData> list = advertisementInService.getAdByConverge(pd);
					 map.put("pd",list);
						result = (null == list) ?  "02" :  "01";
					}else {
						result = "03";
					}	
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	
	/**
	 * 修改点击次数 
	 * @Author zhaozhenhua
	 * @date   2017年12月25日
	 * @return
	 */
	@RequestMapping(value="/editClickCount")
	@ResponseBody
	public Object editClickCount(){
		logBefore(logger, "修改点击次数 ");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("EDITCLICKCOUNT", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("editClickCount", pd)){	//检查参数
					 advertisementInService.editClickCount(pd);
					 result ="01";	
					 }
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	
}
